/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef KH_SLE_HOST_H
#define KH_SLE_HOST_H

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

#include <stdlib.h>
#include "sle_error_code.h"
#include "sle_device_config.h"
#ifndef SLE_HILOG_TAG
#define SLE_HILOG_TAG "SLE_SERVICE"
#endif

/**
 *  @brief  sle host state change callback
 *
 *  @param  [in] state - current sle host device state
 *  @return None
 */
typedef void (*SleHostStateChangeCallback)(SleDeviceState state);

/**
 *  @brief  sle flow monitor event callback
 *
 *  @param  [in] flow - flow
 *  @return None
 */
typedef void (*SleFlowMonitorEventCallback)(float flow);

typedef struct {
    SleHostStateChangeCallback OnSleHostStateChangeCb;
    SleFlowMonitorEventCallback OnSleFlowMonitorEventCb;
} SleHostCallbacks;

/**
 *  @brief  initialize sle service sync
 *
 *  @param  None
 *  @return SleErrorCode - operation result
 */
SleErrorCode InitSleHostService(void);

/**
 *  @brief  deinitialize sle service sync
 *
 *  @param  None
 *  @return SleErrorCode - operation result
 */
SleErrorCode DeinitSleHostService(void);

/**
 *  @brief  enable sle sync
 *
 *  @param  None
 *  @return SleErrorCode - operation result
 *
 *  @note   result return in SleHostTimeOut = 3s
 */
SleErrorCode SleEnable(void);

/**
 *  @brief  disable sle sync
 *
 *  @param  None
 *  @return SleErrorCode - operation result
 *
 *  @note   result return in SleHostTimeOut = 3s
 */
SleErrorCode SleDisable(void);

/**
 *  @brief  get sle state sync
 *
 *  @param  [out] sleHostState - current sle host device state
 *
 *  @return SleErrorCode - operation result
 */
SleErrorCode GetSleState(SleDeviceState* sleHostState);

/**
 *  @brief  get host address sync
 *
 *  @param  [out] addressType -  hostAddr - struct host device
 *  @return SleErrorCode - operation result
 */
SleErrorCode GetHostAddress(SleDeviceAddress *hostAddr);

/**
 *  @brief  set host name sync
 *
 *  @param  [in] name - host name
 *  @param  [in] len - host name length
 *  @return SleErrorCode - operation result
 *
 *  @note   name length must be greater than 0,less than SLE_DEVICE_NAME_LEN = 31，and the name[len-1] must be '\0'
 */
SleErrorCode SetHostName(const uint8_t *name, uint8_t len);

/**
 *  @brief  get host name sync
 *
 *  @param  [out] name -  host name
 *  @param  [out] len -  host name length
 *  @return SleErrorCode - operation result
 */
SleErrorCode GetHostName(uint8_t *name, uint8_t *len);

/**
 *  @brief  get host deault connect param sync
 *
 *  @param  [out] hostConnectConfig - host connect config
 *  @return SleErrorCode - operation result
 */
SleErrorCode GetHostDefaultConnectConfig(SleConnectConfig *hostConnectConfig);

/**
 *  @brief  register host callbacks sync
 *
 *  @param  [in] hostCallback - host callbacks
 *  @return SleErrorCode - operation result
 *
 *  @note   hostCallback should be registered before SleEnable
 */
SleErrorCode RegisterHostCallbacks(SleHostCallbacks *hostCallback);

/**
 *  @brief  unregister host callbacks sync
 *
 *  @param  [in] hostCallback - host callbacks
 *  @return SleErrorCode - operation result
 *
 *  @note   hostCallback should be delete by user after SleDisable
 */
SleErrorCode UnregisterHostCallbacks(SleHostCallbacks *hostCallback);

/**
 *  @brief  read data in the na partition
 * 
 *  @param  [in] key -  key id of the nv item to be read
 *  @param  [in] kvalue_max_length -  maximum length allowed for storing data
 *  @param  [out] kvalue_length -  actual length of data read
 *  @param  [out] kvalue -  pointer to the buffer that stores and reads data
 *  @return SleErrorCode - operation result
 */
SleErrorCode SleUapiNvRead(uint16_t key, uint16_t kvalue_max_length, uint16_t *kvalue_length, uint8_t *kvalue);

/**
 *  @brief  write nv data item
 * 
 *  @param  [in] key -  key id of the nv item to be write
 *  @param  [in] kvalue -  pointer to the value of the NV item to be written
 *  @param  [in] kvalue_length -  The length of data written (in bytes)
 *  @return SleErrorCode - operation result
 */
SleErrorCode SleUapiNvWrite(uint16_t key, const uint8_t *kvalue, uint16_t kvalue_length);

#ifdef __cplusplus
}
#endif // __cplusplus
#endif // SLE_HOST_C__H